﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows;
using Test_01;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using DotnetWork;
using WordList;
using System.Collections.ObjectModel;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

namespace WordsOfLove
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class NewsContent : Page
    {
        public NewsContent()
        {
            this.InitializeComponent();

            //NewsPage newspage = new NewsPage();
            //NewsContentText.Text = newsContent;     /*注释掉错误代码*/
        }
        private ObservableCollection<Word> _matchwordlists = new ObservableCollection<Word>();

        public ObservableCollection<Word> MatchedWordViewLists
        {
            get { return this._matchwordlists; }
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Crawler crawler = new Crawler();
            NewsPage newspage = new NewsPage();
            MatchWordList matchWordList = new MatchWordList();
            NewsList currentlist =(NewsList)e.Parameter;
            string preNewsContent = crawler.GetArticle(currentlist.ContentAd);
            HashSet<Word> MatchedWordList = new HashSet<Word>();
            matchWordList.s = preNewsContent;
            List<Word> gotWordList = MatchWordList.CreateWordList();
            MatchedWordList = matchWordList.markString(gotWordList);
            NewsContentText.Text = matchWordList.s;

            foreach(Word w in MatchedWordList)
            {
                MatchedWordViewLists.Add(w);
            }

            string newsIm = currentlist.ImageAddress;
            NewsImage.Source = new BitmapImage(new Uri(newsIm));
        }

    }

}
